//引入文件模块
const fs = require('fs')
//导入路径定义方法
const path = require('path')

// 创建多个文件夹的函数
exports.ensureDirectoriesExist = (baseDir, subDirs) => {
    subDirs.forEach((subDir) => {
        const fullDirPath = path.join(baseDir, subDir)
        if (!fs.existsSync(fullDirPath)) {
            fs.mkdirSync(fullDirPath, { recursive: true })
            console.log(`目录创建成功: ${fullDirPath}`)
        } else {
            console.log(`目录已存在: ${fullDirPath}`)
        }
    })
}

exports.saveFileToDir = (filePath, fileData) => {
    filePath = path.join('D:/Documents/', filePath)

    // 将文件写入磁盘
    fs.writeFile(filePath, Buffer.from(fileData, 'base64'), (err) => {
        if (err) {
            console.error('保存文件时出错:', err)
        } else {
            console.log('文件保存成功:', filePath)
        }
    })
}
